package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.SicControle;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sisldat8;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela Ctlpc002Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Ctlpc002Report {
	private String nomeClasse;
	private String plac;
	private String tipoD;
	private int datemi;
	private String cabecaGov;
	private int dtini;
	private int dtfim;
	private int dataCorrente;
	private String diacntChassi; // DB
	private String diacntRequer; // DB
	private Long dincntNdemid; // DB
	private Integer dincntMatfun; // DB
	public int datini;
	public int datfim;
	private String nroPagina;
	private String horaCorrente;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicControle vwDvecon = new SicControle();
	SicTabelas vwTabele = new SicTabelas();
	// Classes includes
	Sisldat8 sisldat8 = new Sisldat8();
	Sisll001 sisll001 = new Sisll001();

	public Ctlpc002Report() throws JRException, ParseException {
		inicializar();
	}

	public Ctlpc002Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		nomeClasse = this.getClass().getSimpleName();
		plac = "";
		tipoD = "";
		datemi = 0;
		dtini = 0;
		dtfim = 0;
		dataCorrente = 0;
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", " ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 60, "Cabecagov", "X", "ZZZ.ZZ9", "");
				report.adicionaCampo(119, 7, "lit_119_7", "C", "", "PAGINA:");
				report.adicionaCampo(127, 5, "nroPagina", "S", "ZZZ.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 2);
			{
				report.adicionaCampo(1, 43, "lit_1_43", "C", "", "SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA");
				report.adicionaCampo(119, 14, "lit_119_14", "C", "", "REL.  CTLPC002");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 6);
			{
				report.adicionaCampo(1, 45, "lit_1_45", "C", "", "RELACAO DOS DOCUMENTOS EMITIDOS NO PERIODO DE");
				report.adicionaCampo(47, 8, "Dtini", "N", "99/99/9999", "");
				report.adicionaCampo(56, 1, "lit_56_1", "C", "", "A");
				report.adicionaCampo(58, 8, "Dtfim", "N", "99/99/9999", "");
				report.adicionaCampo(119, 5, "lit_119_5", "C", "", "DATA:");
				report.adicionaCampo(125, 8, "dataCorrente", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 7);
			{
				report.adicionaCampo(1, 21, "lit_1_21", "C", "", "CHASSIS/PRONTUARIO/RG");
				report.adicionaCampo(27, 5, "lit_27_5", "C", "", "PLACA");
				report.adicionaCampo(35, 15, "lit_35_15", "C", "", "NOME REQUERENTE");
				report.adicionaCampo(71, 16, "lit_71_16", "C", "", "NUMERO DOCUMENTO");
				report.adicionaCampo(92, 14, "lit_92_14", "C", "", "TIPO DOCUMENTO");
				report.adicionaCampo(117, 7, "lit_117_7", "C", "", "EMISSAO");
				report.adicionaCampo(125, 7, "lit_125_7", "C", "", "MAT.FUN");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 7);
			{
				report.adicionaCampo(1, 25, "Diacntchassi", "X", "", "");
				report.adicionaCampo(27, 7, "Plac", "X", "", "");
				report.adicionaCampo(35, 35, "Diacntrequer", "X", "", "");
				report.adicionaCampo(71, 13, "Dincntndemid", "N", "99/99/9999", "");
				report.adicionaCampo(90, 23, "Tipod", "X", "99/99/9999", "");
				report.adicionaCampo(114, 8, "Datemi", "N", "99/99/9999", "");
				report.adicionaCampo(125, 7, "Dincntmatfun", "N", "ZZZZ999", "");
				report.setFimLinhaRel();
			}
		}
		cabecaGov = "SECRETARIA DE ESTADO DO PLANEJAMENTO E ORCAMENTO - SEPLAN";
		horaCorrente = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()); // *TIMX
		setCabecagov(cabecaGov);
		setHoraCorrente(horaCorrente);
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public String getPlac() {
		return plac;
	}

	public void setPlac(String plac) throws ParseException {
		this.plac = plac;
		report.adicionaValorReport("Plac", plac);
	}

	public String getTipod() {
		return tipoD;
	}

	public void setTipod(String tipoD) throws ParseException {
		this.tipoD = tipoD;
		report.adicionaValorReport("Tipod", tipoD);
	}

	public int getDatemi() {
		return datemi;
	}

	public void setDatemi(int datemi) throws ParseException {
		this.datemi = datemi;
		report.adicionaValorReport("Datemi", datemi);
	}

	public String getCabecagov() {
		return cabecaGov;
	}

	public void setCabecagov(String cabecaGov) throws ParseException {
		this.cabecaGov = cabecaGov;
		report.adicionaValorReport("Cabecagov", cabecaGov);
	}

	public int getDtini() {
		return dtini;
	}

	public void setDtini(int dtini) throws ParseException {
		this.dtini = dtini;
		report.adicionaValorReport("Dtini", dtini);
	}

	public int getDtfim() {
		return dtfim;
	}

	public void setDtfim(int dtfim) throws ParseException {
		this.dtfim = dtfim;
		report.adicionaValorReport("Dtfim", dtfim);
	}

	public int getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(int dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public String getHoraCorrente() {
		return horaCorrente;
	}

	public void setHoraCorrente(String horaCorrente) throws ParseException {
		this.horaCorrente = horaCorrente;
		report.adicionaValorReport("horaCorrente", horaCorrente);
	}

	public int getDatfim() {
		return datfim;
	}

	public void setDatfim(int datfim) throws ParseException {
		this.datfim = datfim;
		report.adicionaValorReport("Datfim", datfim);
	}

	public int getDatini() {
		return datini;
	}

	public void setDatini(int datini) throws ParseException {
		this.datini = datini;
		report.adicionaValorReport("Datini", datini);
	}

	public String getDiacntchassi() {
		return diacntChassi;
	}

	public void setDiacntchassi(String diacntChassi) throws ParseException {
		this.diacntChassi = diacntChassi;
		report.adicionaValorReport("Diacntchassi", diacntChassi);
	}

	public String getDiacntrequer() {
		return diacntRequer;
	}

	public void setDiacntrequer(String diacntRequer) throws ParseException {
		this.diacntRequer = diacntRequer;
		report.adicionaValorReport("Diacntrequer", diacntRequer);
	}

	public Integer getDincntmatfun() {
		return dincntMatfun;
	}

	public void setDincntmatfun(Integer dincntMatfun) throws ParseException {
		this.dincntMatfun = dincntMatfun;
		report.adicionaValorReport("Dincntmatfun", dincntMatfun);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}
}
